package com.webbei.Backstage.dao.impl;


import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.taobao.api.ApiException;
import com.taobao.api.domain.Refund;
import com.taobao.api.request.RefundGetRequest;
import com.taobao.api.response.RefundGetResponse;
import com.wabbei.fenxiao.action.MyTaobaoUtil;
import com.webbei.Backstage.dao.BackstateDao;
import com.webbei.Backstagepojo.Labelcost;
import com.webbei.pojo.Advertisement;
import com.webbei.pojo.BgPic;
import com.webbei.pojo.Brands;
import com.webbei.pojo.Carseries;
import com.webbei.pojo.Cartypes;
import com.webbei.pojo.Customer;
import com.webbei.pojo.Customerlimit;
import com.webbei.pojo.Customs;
import com.webbei.pojo.Designers;
import com.webbei.pojo.IndusConproduct;
import com.webbei.pojo.Industry;
import com.webbei.pojo.Label;
import com.webbei.pojo.LabelInfo;
import com.webbei.pojo.LabelProduct;
import com.webbei.pojo.Managers;
import com.webbei.pojo.OrderStatistics;
import com.webbei.pojo.Ordercost;
import com.webbei.pojo.Orders;
import com.webbei.pojo.PrintInfo;
import com.webbei.pojo.Products;
import com.webbei.pojo.RefundOrder;
import com.webbei.pojo.Report;
import com.webbei.pojo.Userhot;
import com.webbei.product.action.Product;

public class BackstateDaoImpl implements BackstateDao {
       private SqlSession session;

    /*  public SqlSession getSession() {
		return session;
	}*/

	public void setSession(SqlSession session) {
		this.session = session;
	}

	@Override
	public List<Report> relist(int start) {
		return session.selectList("report.getall",start);
	}

	@Override
	public List<Managers> malist() {
		return session.selectList("manager.getall");
	}

	@Override
	public List<Customer> cuslist() {
		return session.selectList("customer.getUsername");
	}

	@Override
	public Customer findcusbyid(int id) {
		return (Customer) session.selectOne("customer.getCustomer", id);
	}

	@Override
	public List<Customer> fenyelist(int start) {
		return session.selectList("customer.getcusfenye",start);
	}

	@Override
	public List<Customer> findcusbyname(String uname) {
		 return  session.selectList("customer.getCustomerByUserName", "%"+uname+"%");
	}

	@Override
	public int getreortCount() {
		return (Integer) session.selectOne("report.getcount");
	}

	@Override
	public int reportsuccess(String username,int count,int reportId) {
		Userhot hot=new Userhot();
		hot.setUserName(username);
		hot.setBereportedCount(count);
		session.update("report.pass",reportId);
		return session.update("userhot.upbereportCount",hot);
	}

	@Override
	public int reportfail(String username,int count,int reportId) {
		Userhot hot=new Userhot();
		hot.setUserName(username);
		hot.setReportfailCount(count);
		session.update("report.unPass",reportId);
		return session.update("userhot.upreportfailCount",hot);
	}

	@Override
	public Userhot uhot(String username) {

		Userhot hot=(Userhot) session.selectOne("userhot.getUserhotByUsername",username);
	   return hot;
	}

	@Override
	public int customerlimitCount() {
	  return (Integer) session.selectOne("cuslimit.getlimitCount");
	}

	@Override
	public List<Customerlimit> cuslimitlist(int start) {
		  return session.selectList("cuslimit.getall",start);
	}

	@Override
	public int updatelimit(String name, int share, int ping, int ju, int ding) {
		Customerlimit limi=new Customerlimit();
		limi.setUserName(name);
		limi.setCanShare(share);
		limi.setCanCustom(ding);
		limi.setCanComment(ping);
		limi.setCanReport(ju);
		return session.update("cuslimit.updatelimit",limi);
	}

	@Override
	public Customerlimit cuslimi(String username) {
		return (Customerlimit) session.selectOne("cuslimit.getonelimi", username);
	}

	@Override
	public List<Report> getrecontent(String bename) {
		return session.selectList("report.getrecontent",bename);
	}

	@Override
	public List<Industry> getallinformation() {
	 return session.selectList("Mindustry.getinduinformation");
	}



       public int deleteindus(int id){
    	  return session.delete("Mindustry.deleteindus", id);
       }

	@Override
	public Industry getone(int id) {
		return (Industry) session.selectOne("Mindustry.getone",id);
	}


	public List<Orders> orderlist(int start) {
		return session.selectList("orders.getOrder",start);
	}

	public int getOrdercount(String datetime,String indusname,Long orderId){
		System.out.println("time=="+datetime+"indusname=="+indusname);

		Map map=new HashMap();
		map.put("indusname",indusname);
		map.put("datetime", datetime);
		map.put("orderId", orderId);
		 return (Integer) session.selectOne("orders.getorderCount1",map);
		/*int count = 0;
		if(!datetime.equals("kong")&&!indusname.equals("kong")){
			map.put("indusname",indusname);
			map.put("datetime", datetime);
	     	count=(Integer) session.selectOne("orders.getorderCount3",map);
		}
			if(!datetime.equals("kong")&&indusname.equals("kong"))
			{
				System.out.println("jinlale");
			 map.put("datetime", datetime);
			 count=(Integer) session.selectOne("orders.getorderCount1",map);
			}

		if(!indusname.equals("kong")&&datetime.equals("kong"))
	    {
			//System.out.println("jinlaile");
			map.put("indusname",indusname);
		     count=(Integer) session.selectOne("orders.getorderCount2",map);
			}

		return count;*/
	}

	@Override
	/*public Orders getorder(int orderid) {
		return (Orders) session.selectOne("orders.getOrdersById", orderid);
	}*/
	public Orders getorder(Long orderid) {
		return (Orders) session.selectOne("orders.getOrdersById", orderid);
	}

	@Override
	public String getindusNamebyid(int id) {
	return  (String) session.selectOne("Mindustry.getindusNamebyid", id);
	}

	/*@Override
	public int updCDRstateAndinCdrpath(String path,int orderid) {
		Orders order=new Orders();
		order.setCDRurl(path);
		order.setOrderId(orderid);
		return session.update("orders.insertCDRpath",order);
	}*/
	public int updCDRstateAndinCdrpath(String path,Long orderid) {
		Orders order=new Orders();
		order.setCDRurl(path);
		order.setOrderId(orderid);
		return session.update("orders.insertCDRpath",order);
	}
	@SuppressWarnings("rawtypes")
	@Override
	public List<Orders> getorderByday(String day,String indusname,Long orderId,int start) {
		Map map=new HashMap();
		List<Orders> list=new ArrayList<Orders>();
		map.put("day", day);
		map.put("indusname", indusname);
		map.put("orderId", orderId);
		map.put("start", start);
		 list=session.selectList("orders.getOrderbyday1",map);
		/*if(!day.equals("kong")&&!indusname.equals("kong")){
		map.put("day", day);
		map.put("indusname", indusname);
		map.put("start", start);
	    list=session.selectList("orders.getOrderbyday1",map);
		}
		if(!day.equals("kong")&&indusname.equals("kong")){
				map.put("day",day);
				map.put("start", start);
				 list=session.selectList("orders.getOrderbyday2",map);
			}
			if(!indusname.equals("kong")&&day.equals("kong")){
				map.put("indusname",indusname);
				map.put("start", start);
				 list=session.selectList("orders.getOrderbyday3",map);
			}
		*/
		return list;
	}

	@Override
	 public int getOrdercountByindusid(String datetime,int indusid,String uname,int orderstate) {
		Map map=new HashMap();
		map.put("datetime",datetime);
		map.put("indusid", indusid);
		map.put("uname",uname);
		map.put("orderstate",orderstate);
		return (Integer) session.selectOne("orders.getindusCount",map);
	}

	@Override
	public List<Orders> getindusorderByday(String day,int start,int indusid,String uname,int orderstate) {
		Map map=new HashMap();
		map.put("datetime", day);
		map.put("start", start);
		map.put("indusid", indusid);
		map.put("uname", uname);
		map.put("orderstate", orderstate);
		return session.selectList("orders.getindusOrder",map);
	}

	@Override
	public String getconmentcontentbyid(int id) {
		String str=(String)session.selectOne("Customcomment.getcommentContent",id);
		return str;
	}

	 public int deletecomment(int commentid){
		 return session.delete("Customcomment.deletecomment",commentid);
	 }

	@Override
	public int updateindus(int id, String industryName, String industryAddress,
			String industryPrincipal, String industryTel, String industryEmail) {
		Industry dus=new Industry();
		dus.setIndustryAddress(industryAddress);
		dus.setIndustryEmail(industryEmail);
		dus.setIndustryId(id);
		dus.setIndustryName(industryName);
		dus.setIndustryprincipal(industryPrincipal);
		dus.setIndustryTelephone(industryTel);
	  return session.update("Mindustry.updateinfomation",dus);
	}

	@Override
	public int addindus(String industryName, String industryAddress,
			String industryPrincipal, String industryTel, String industryEmail) {
         Industry ins=new Industry();
				 ins.setIndustryName(industryName);
				 ins.setIndustryprincipal(industryPrincipal);
				 ins.setIndustryAddress(industryAddress);
				 ins.setIndustryEmail(industryEmail);
				 ins.setIndustryTelephone(industryTel);
				 return session.insert("Mindustry.insertindus",ins);
	}

	@Override
	public String getproductNamebyid(int proid) {
	 String str=(String)session.selectOne("Products.getpronamebyID",proid);
	 return str;
	}


	public List<Products> gotoAddindus() {
	return session.selectList("Products.getProducts2");
	}


	public int updatecommentIdInreport(int reportid) {
		Report re=new Report();
		re.setReportId(reportid);
		re.setCommentId(-1);
		return session.update("report.updatecommentid", re);
	}

	@Override
	public List<String> proName(int indusid) {
		Map map=new HashMap();
		map.put("indusid",indusid);
		return session.selectList("indusconpro.getprobyindusid",map);
	}

	 public int insertinconpro(int indusid,int proid){
		 IndusConproduct dus=new IndusConproduct();
		 dus.setIndustryId(indusid);
		 dus.setProductId(proid);
		 return session.insert("indusconpro.insertproid",dus);
	 }

	 public int getindusIdbyName(String name){
		 return (Integer) session.selectOne("Mindustry.getindusidbyName", name);
	 }

	@Override
	public int deleteproidByindusid(int indusid) {
		 return session.delete("indusconpro.deleteprobyindusid",indusid);
	}

	@Override
	public List<String> moren(int indusid) {
		Map map=new HashMap();
		map.put("indusid",indusid);
		return session.selectList("indusconpro.getmorenProduct",map);
	}

	 public int updatexuanzhong(int indusid,String proname){
		Map map=new HashMap();
		map.put("indusid", indusid);
		map.put("proId", proname);

		for(Object o:map.keySet()){
		  System.out.println("aaaaaa:"+map.get(o));
		}
		 return session.update("indusconpro.updatexuanzhong2",map);
	 }
	    public int updateExceptxuanzhong(int indus,String proname){
	    	Map map=new HashMap();
			map.put("indusid", indus);
			map.put("proname", proname);
			 return session.update("indusconpro.updateExceptxuan",map);
	    }

		@Override
		public List getCostnameandCostmoney(int backpicid) {
			System.out.println("~~~~~~~~~~~~~~"+backpicid);
			//System.out.println("jinlaile");
			//Map map=new HashMap();
			List<Labelcost> result=new ArrayList<Labelcost>();
			List list=new ArrayList();
			list=session.selectList("orders.getCostNameandCostmoney",backpicid);
			//System.out.println("chulaile");
			/* Collection c = map.values();
		        Iterator it = c.iterator();
		        for (; it.hasNext();) {
		            System.out.println(it.next());
		        }*/
			for(int i=0;i<list.size();i++){
				Map map=(Map) list.get(i);

				//System.out.println(map);
				/*Iterator iter = map.entrySet().iterator();
				while (iter.hasNext()) {
				Map.Entry entry = (Map.Entry) iter.next();
				Object key = entry.getKey();
				Object val = entry.getValue();*/
				Labelcost l=new Labelcost();
				l.setLabelcostmoney((Double)map.get("labelcostMoney"));
				l.setLabelcostname((String)map.get("labelcostName"));
				result.add(l);
			}



		    return result;
		}

		@Override
		/*public int updateOrderstate(int orderid) {
			return session.update("orders.updateOrderstate",orderid);
		}*/
		public int updateOrderstate(Long orderid,String orderNumber) {
			Map<String,Object> m=new HashMap<String,Object>();
			m.put("tradeId",orderid);
			m.put("orderNumber",orderNumber);
			return session.update("orders.updateOrderstate",m);
		}
		@Override
	/*	public int updateStockout(int orderid, String liyou) {
			Orders or=new Orders();
			or.setOrderId(orderid);
			or.setStockoutReason(liyou);
			return session.update("orders.stockoutreason",or);

		}*/
		public int updateStockout(Long orderid, String liyou) {
			Orders or=new Orders();
			or.setOrderId(orderid);
			or.setStockoutReason(liyou);
			return session.update("orders.stockoutreason",or);

		}

		@Override
		/*public int updateFeedbackreson(int orderid, String reason) {
			Orders or=new Orders();
			or.setOrderId(orderid);
			or.setCostFeedback(reason);

			return session.update("orders.updateFeedback", or);
		}*/
		public int updateFeedbackreson(Long orderid, String reason) {
			Orders or=new Orders();
			or.setOrderId(orderid);
			or.setCostFeedback(reason);

			return session.update("orders.updateFeedback", or);
		}

		@Override
		public int insertcost(Ordercost orcost) {
			return session.insert("ordermoneycost.insertmoneycost", orcost);
		}

		@Override
		/*public List<Orders> orderlist(int orderid,String ordername,int indusid, String time1, String time2,int start) {
			Map map=new HashMap();
			map.put("t1", time1);

			if(orderid==-1)
				map.put("orid",-1);
			else
				map.put("orid",orderid);

			if(time1!=""&&time1!=null){
			if(time2.equals("")||time2==null){
				    Date t=new Date();
			        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			        String dateString = formatter.format(t);
			        //System.out.println("zhelidedate:"+dateString);
			        map.put("t2",dateString);
			}
			else
			{
			map.put("t2", time2);
			}
			}
			map.put("indusid", indusid);
			map.put("orname",ordername);
			map.put("start", start);
			return session.selectList("orders.getorderForCost",map);
		}*/
		public List<Orders> orderlist(Long orderid,String ordername,int indusid, String time1, String time2,int start) {
			Map map=new HashMap();
			map.put("t1", time1);

			if(orderid==-1)
				map.put("orid",-1);
			else
				map.put("orid",orderid);

			if(time1!=""&&time1!=null){
			if(time2.equals("")||time2==null){
				    Date t=new Date();
			        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			        String dateString = formatter.format(t);
			        //System.out.println("zhelidedate:"+dateString);
			        map.put("t2",dateString);
			}
			else
			{
			map.put("t2", time2);
			}
			}
			map.put("indusid", indusid);
			map.put("orname",ordername);
			map.put("start", start);
			return session.selectList("orders.getorderForCost",map);
		}

		 public List<Ordercost> ordercost(){
			 List<Ordercost> list=session.selectList("ordermoneycost.getallordercost");
			 return list;
		 }
		 /*public Ordercost getoneordercost(int orderid){
			 return (Ordercost) session.selectOne("ordermoneycost.getone",orderid);
		 }*/
		public Ordercost getoneordercost(Long orderid){
			 return (Ordercost) session.selectOne("ordermoneycost.getone",orderid);
		 }

		@Override
		/*public List<Orders> allindusorderlist(int orderid,String ordername,int indusid, String time1,
				String time2,int start) {
			Map map=new HashMap();
			map.put("t1", time1);

			if(time1!=""&&time1!=null){
			if(time2.equals("")||time2==null){
				    Date t=new Date();
			        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			        String dateString = formatter.format(t);
			        System.out.println("zhelidedate:"+dateString);
			        map.put("t2",dateString);
			}
			else
			{
			map.put("t2", time2);
			}
			}
			if(orderid==-1){
				map.put("orid",-1);
			}
			else{
				map.put("orid",orderid);
			}

			if(indusid==-1)
			{
				System.out.println("woshi:"+indusid);
				map.put("indusid",-1);
			}
			else
			map.put("indusid",indusid);

			map.put("orname",ordername);
			map.put("start", start);
			return session.selectList("orders.getallindusorderForCost", map);
		}*/
		public List<Orders> allindusorderlist(Long orderid,String ordername,int indusid, String time1,
				String time2,int start) {
			Map map=new HashMap();
			map.put("t1", time1);

			if(time1!=""&&time1!=null){
			if(time2.equals("")||time2==null){
				    Date t=new Date();
			        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			        String dateString = formatter.format(t);
			        System.out.println("zhelidedate:"+dateString);
			        map.put("t2",dateString);
			}
			else
			{
			map.put("t2", time2);
			}
			}
			if(orderid==-1){
				map.put("orid",-1);
			}
			else{
				map.put("orid",orderid);
			}

			if(indusid==-1)
			{
				System.out.println("woshi:"+indusid);
				map.put("indusid",-1);
			}
			else
			map.put("indusid",indusid);

			map.put("orname",ordername);
			map.put("start", start);
			return session.selectList("orders.getallindusorderForCost", map);
		}
		@Override
		/*public String get9dingid(int orderid) {
			String dd=orderid+"";
			String str="";
			if(dd.length()<9){
				 DecimalFormat df=new DecimalFormat("000000000");
				  str=df.format(orderid);
			}
			else{
				str=dd;
			}
			return str;
		}*/
		public String get9dingid(Long orderid) {
			String dd=orderid+"";
			String str="";
			if(dd.length()<9){
				 DecimalFormat df=new DecimalFormat("000000000");
				  str=df.format(orderid);
			}
			else{
				str=dd;
			}
			return str;
		}

		@Override
		public String chaifendingid(String dingid) {
			 return dingid.replaceAll("^(0+)", "");
         }

		@Override
		/*public int getoneOrdercostCount(int orerid, String ordername,
				int indusid, String time1, String time2) {
			Map map=new HashMap();
			map.put("t1", time1);

			if(orerid==-1)
				map.put("orid",-1);
			else
				map.put("orid",orerid);

			if(time1!=""&&time1!=null){
			if(time2.equals("")||time2==null){
				    Date t=new Date();
			        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			        String dateString = formatter.format(t);
			        map.put("t2",dateString);
			}
			else
			{
			map.put("t2", time2);
			}
			}
			map.put("indusid", indusid);
			map.put("orname",ordername);
			return (Integer) session.selectOne("orders.CountorderForCost", map);
		}*/
		public int getoneOrdercostCount(Long orerid, String ordername,
				int indusid, String time1, String time2) {
			Map map=new HashMap();
			map.put("t1", time1);

			if(orerid==-1)
				map.put("orid",-1);
			else
				map.put("orid",orerid);

			if(time1!=""&&time1!=null){
			if(time2.equals("")||time2==null){
				    Date t=new Date();
			        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			        String dateString = formatter.format(t);
			        map.put("t2",dateString);
			}
			else
			{
			map.put("t2", time2);
			}
			}
			map.put("indusid", indusid);
			map.put("orname",ordername);
			return (Integer) session.selectOne("orders.CountorderForCost", map);
		}

		@Override
		public int allOrdercostCount(Long orderid, String ordername,
				int indusid, String time1, String time2) {
			Map map=new HashMap();
			map.put("t1", time1);

			if(time1!=""&&time1!=null){
			if(time2.equals("")||time2==null){
				    Date t=new Date();
			        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			        String dateString = formatter.format(t);
			        System.out.println("zhelidedate:"+dateString);
			        map.put("t2",dateString);
			}
			else
			{
			map.put("t2", time2);
			}
			}
			if(orderid==-1){
				map.put("orid",-1);
			}
			else{
				map.put("orid",orderid);
			}

			if(indusid==-1)
			{
				System.out.println("woshi:"+indusid);
				map.put("indusid",-1);
			}
			else
			map.put("indusid",indusid);

			map.put("orname",ordername);

			return (Integer) session.selectOne("orders.CountallindusorderForCost", map);
		}

		/*public int allOrdercostCount(int orderid, String ordername,
		int indusid, String time1, String time2) {
	Map map=new HashMap();
	map.put("t1", time1);

	if(time1!=""&&time1!=null){
	if(time2.equals("")||time2==null){
		    Date t=new Date();
	        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
	        String dateString = formatter.format(t);
	        System.out.println("zhelidedate:"+dateString);
	        map.put("t2",dateString);
	}
	else
	{
	map.put("t2", time2);
	}
	}
	if(orderid==-1){
		map.put("orid",-1);
	}
	else{
		map.put("orid",orderid);
	}

	if(indusid==-1)
	{
		System.out.println("woshi:"+indusid);
		map.put("indusid",-1);
	}
	else
	map.put("indusid",indusid);

	map.put("orname",ordername);

	return (Integer) session.selectOne("orders.CountallindusorderForCost", map);
}
	/*	public String getCdrurlByorderid(int orderid) {
			return (String) session.selectOne("orders.getcdrurl",orderid);
		}*/
		public String getCdrurlByorderid(Long orderid) {
			return (String) session.selectOne("orders.getcdrurl",orderid);
		}

		public List<Brands> getAllBrands() {
			List<Brands> list=null;
			list=session.selectList("Brands.getAllBrands");
			return list;
		}

		@Override
		public int insertNewCarseries(Carseries car) {
			int i=session.insert("Carseries.insertNewCarseries", car);
			return i;
		}

		@Override
		public int insertNewCarTypes(Cartypes cartype) {
			int i=session.insert("cartype.insertNewCarTypes", cartype);
			return i;
		}

		@Override
		public int getCarseriesIdBySeriesName(String newCarName) {
			int i=(Integer) session.selectOne("Carseries.getCarseriesId", newCarName);
			return i;

		}

		@Override
		public List<Carseries> getAllCarSeriesByBrandId(int brandId) {
			List<Carseries> list=null;
			list=session.selectList("Carseries.getCarseriesByBrandId",brandId);
			return list;
		}

		@Override
		public List<Cartypes> getAllCarTypesBySeriesId(int seriesId) {
			List<Cartypes> list=null;
			list=session.selectList("cartype.getAllCartypesBySeriesId",seriesId);
			return list;
		}

		@Override
		public int deleteCarTypesBycartypeid(int cartypeid) {
			return session.delete("cartype.deleteCarTypeByCarTypeId", cartypeid);
		}

		@Override
		public int checkUserNamePwd(Map<String, String> map) {
			return (Integer)session.selectOne("manager.checkUserName",map);
		}

		@Override
		public int updatePwdByUserName(Map<String, String> map) {
			return (Integer)session.update("manager.updataPwd", map);
		}

		@Override
		public int chackTheNewCarName(String newCarName) {
			int i= (Integer)session.selectOne("Carseries.checksidbyusername", newCarName);
			return i;
		}

		@Override
		public int insertNewBrand(String brandName) {

			return session.insert("Brands.insertnewbrand", brandName);
		}

		@Override
		public int checkBrandName(String brandName) {
			// TODO Auto-generated method stub
			return (Integer)session.selectOne("Brands.checkbrandname", brandName);
		}

		@Override
		public int checkCartypeHaveSeriesId(int seriesId) {
			// TODO Auto-generated method stub
			return (Integer)session.selectOne("cartype.checkseriesid", seriesId);
		}

		@Override
		public int deleteCarSeriesBySeriesId(int seriesId) {
			// TODO Auto-generated method stub
			return session.delete("Carseries.deleteCarseriesBySeriesId", seriesId);
		}

		@Override
		public int deleteCarTypesBySeriesId(int seriesId) {
			// TODO Auto-generated method stub
			return session.delete("cartype.deletebyseriesid",seriesId);
		}

		@Override
		public int deleteCarBrandByBrandId(int brandId) {
			return session.delete("Brands.deleteBrandsById",brandId);
		}

		@Override
		public int checkProductName(String productName) {
			// TODO Auto-generated method stub
			return (Integer)session.selectOne("Products.checkproductname", productName);
		}

		@Override
		public int insertNewProduct(Map<String, Object> m){
			return session.insert("Products.insertnewproduct", m);
		}

		@Override
		public List<Products> getAllProducts() {
			List<Products> list=null;
			list=session.selectList("Products.getProducts");
			return list;
		}

		@Override
		public int chackThelabelName(String labelName) {
			return (Integer)session.selectOne("label.checklabelname", labelName);
		}

		@Override
		public int insertNewLabel(String labelName) {
			return session.insert("label.insertnewlabel", labelName);
		}

		@Override
		public int getLabelIdByLabelName(String labelName) {
			// TODO Auto-generated method stub
			System.out.println("labelName:"+labelName);
			Integer id = (Integer)session.selectOne("label.getlabelId", labelName);
			int id1=0;
			if(id!=null){
				id1 = id;
			}
			System.out.println("id1:"+id);
			return id1;
		}

		@Override
		public int createNewProductconLabel(Map<String, Integer> m) {
			return session.insert("productconlabel.newprolab",m);

		}

		@Override
		public int getProLabIdByPidAndLid(Map<String, Integer> m) {
			return (Integer)session.selectOne("productconlabel.getprolabid", m);
		}

		@Override
		public int newBackPic(Map b) {
			return session.insert("BgPic.newbackpic",b);
		}

		@Override
		public List<Label> getLabelIdByProductId(int productId) {
			List<Label> list=null;
			list=session.selectList("label.getlabelsbyproductid",productId);
			return list;
		}

		@Override
		public double getPriceByProLabId(int prolabid) {
			return (Double)session.selectOne("BgPic.getpricebyprolabid", prolabid);
		}

		@Override
		public int getProLabIdByLabelId(int lid) {
			return (Integer)session.selectOne("productconlabel.getprolabidbylid", lid);
		}

		@Override
		public int deleteLabelByLid(int lid) {
			return session.delete("label.deleteLabelByLid", lid);
		}

		@Override
		public List<BgPic> getBgPicByProLabId(Integer prolabid) {
			return session.selectList("BgPic.getBgPicByProLabId",prolabid);
		}

		@Override
		public int deleteBgPicByProLabId(Integer prolabid) {
			return session.delete("BgPic.deleteBgPicByProLabId", prolabid);
		}

		@Override
		public void deleteProductLabelByLabelId(int lid) {
			session.delete("productconlabel.DeleteByLid", lid);

		}

		@Override
		public void deleteProductByProductId(int productId) {
			session.delete("Products.deleteProductByPid",productId );

		}

		@Override
		public int checkProLabByProductId(int productId) {
			return (Integer)session.selectOne("productconlabel.checkPid", productId);
		}

		@Override
		public List<BgPic> getBgPicByProductId(int productId) {
			List<BgPic> list=null;
			list=session.selectList("BgPic.getPicByPid",productId);
			return list;
		}

		@Override
		public int deleteLabelPicByPicUrl(String picUrl) {
			return session.delete("BgPic.deletebypicurl", picUrl);
		}

		@Override
		public void deleteIndustProductByPid(int productId) {
			session.delete("indusconpro.deletebyproductId", productId);
		}

		@Override
		public void updateExceptxuanzhong(int id) {
			session.update("indusconpro.updateById",id);

		}

		@Override
		public int checkLabelName(String labelName) {
			return (Integer)session.selectOne("label.checklabelname",labelName);

		}

		@Override
		public List<Customs> getAllNotReviewCustoms() {
			return session.selectList("cust.getallnotreviewcustoms");
		}

		@Override
		public int updateCustomReviewByCustomId(long customid) {
			return session.update("cust.updatecustomreviewbycid", customid);
		}

		@Override
		public List<Customs> getAllReviewCustoms() {
			return session.selectList("cust.getallreviewcustoms");
		}

		@Override
		public int updateCustomShareByCustomId(long customid) {
			return session.update("cust.updatecustomsharebycid", customid);
		}

		@Override
		public int checkBrandSeries(String newCarName, int brandId) {
			Map<String,Object> m=new HashMap<String,Object>();
			m.put("newCarName",newCarName);
			m.put("brandId",brandId);
			return (Integer)session.selectOne("Carseries.checkbrandseries",m);
		}

		@Override
		public int insertNewAdvertisment(Map<String, Object> m) {
			// TODO Auto-generated method stub
			System.out.println(m);
			return session.insert("advertisment.newadvertisment",m);
		}

		@Override
		public List<Advertisement> getAllAdvertisment() {
			List<Advertisement> list=null;
			list=session.selectList("advertisment.getalladvertisment");
			return list;
		}

		@Override
		public void clearAllTheAdvertismentShow() {
			// TODO Auto-generated method stub
			session.update("advertisment.clearalltheshow");
		}

		@Override
		public void setTheAdvIsShowById(int id,String address) {
			Map<String,Object> m = new HashMap<String,Object>();
			m.put("id",id);
			m.put("address",address);
			System.out.println("setTheAdvIsShowById:"+m);
			session.update("advertisment.setadvisshow",m);

		}

		@Override
		public int deleteAdvertismentById(int imageId) {
			// TODO Auto-generated method stub
			return session.delete("advertisment.deleteadvertismentbyid", imageId);
		}

		@Override
		public List<Product> getAllProduct() {
			return session.selectList("Products.getAllProducts2");
		}

		@Override
		public void changePostion(String jsonString, int id) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("productId", id);
			map.put("autoLogos",jsonString);
			session.update("Products.changePosition", map);
		}

		@Override
		public String getCustomerMailByUid(int id) {
			// TODO Auto-generated method stub
			return (String)session.selectOne("customer.getMail",id);
		}

		@Override
		public Designers getDesignersByMail(String mail) {
			return (Designers)session.selectOne("designers.getthedesignersbymail",mail);
		}

		@Override
		public List<Label> getAllLabelAndIsReviewzero() {
			List<Label> list=null;
			list=session.selectList("label.getalllabelisreviewzero");
			return list;
		}

		@Override
		public Customer getCustomerByUsername(String username) {
			System.out.println("username:"+username);
			return (Customer)session.selectOne("customer.getCustomerByUserName",username);
		}

		@Override
		public int updateLabelReview(int labelId, int isReview) {
			Map<String,Object> m=new HashMap<String,Object>();
			m.put("labelId",labelId);
			m.put("isReview", isReview);
			// TODO Auto-generated method stub
			return session.update("label.updateisreviewbylid", m);
		}

		@Override
		public List<Products> getIndusPros(int id) {
			// TODO Auto-generated method stub
			return session.selectList("Products.getIndusPros",id);
		}

		@Override
		public int getOrdercount(String startTime, String endTime,
				String indusname, Long orderId) {
			Map map=new HashMap();
			map.put("indusname",indusname);
			map.put("startTime", startTime);
			map.put("endTime", endTime);
			map.put("orderId", orderId);
			 return (Integer) session.selectOne("orders.getorderCount2",map);
		}

		@Override
		public List<Orders> getorderByday(String startTime, String endTime,
				String indusname, Long orderId, int start) {
			Map map=new HashMap();
			List<Orders> list=new ArrayList<Orders>();
			map.put("startTime", startTime);
			map.put("endTime", endTime);
			map.put("indusname", indusname);
			map.put("orderId", orderId);
			map.put("start", start);
			 list=session.selectList("orders.getOrderbyday2",map);

			return list;
		}

		@Override
		public void updateOtherCustomReiew() {
			session.update("cust.updateOtherCustomReiew");

		}

		@Override
		public int getOrdercount(Map<String, Object> m) {
			// TODO Auto-generated method stub
			return (Integer) session.selectList("orders.getorderCount3",m).size();
		}

		@Override
		public List<Orders> getorderByday(Map<String, Object> m) {
			return session.selectList("orders.getOrderbyday3",m);
		}

		@Override
		public List<com.webbei.pojo.Labelcost> getLabelCost() {
			// TODO Auto-generated method stub

			return session.selectList("labelcost.getLabelCosts");
		}

		@Override
		public void addCostLabel(String name) {
			session.update("labelcost.addCostLabel",name);

		}

		@Override
		public void deleteLabelCostById(int id) {
			session.update("labelcost.deleteLabelCostById",id);

		}

		@Override
		public LabelInfo getLabelById(int labelId) {
			// TODO Auto-generated method stub
			return (LabelInfo) session.selectOne("label.getLabelById2",labelId);
		}

		@Override
		public List<com.webbei.pojo.Labelcost> getLabelCostByLabelId(int labelId) {
			// TODO Auto-generated method stub
			return session.selectList("labelcost.getLabelCostByLabelId",labelId);
		}

		@Override
		public void deleteLabelconlabelcostByLabelId(int labelId) {
			session.update("labelconlabelcost.deleteLabelconlabelcostByLabelId",labelId);

		}

		@Override
		public void insertLabelconlabelcostByMap(Map<String, Object> m) {
			session.update("labelconlabelcost.insertLabelconlabelcostByMap",m);

		}

		@Override
		public int getLabelIdByPicId(Integer picId) {
			// TODO Auto-generated method stub
			Integer id = (Integer) session.selectOne("label.getLabelIdByPicId",picId);
			if(id!=null){
				return id;
			}else{
			return 0;
			}
		}

		@Override
		public int insertNewLabel(Map<String, Object> labelMap) {
			// TODO Auto-generated method stub
			System.out.println("labelMap"+labelMap);
			return session.insert("label.insertNewLabelByMap", labelMap);
		}

		@Override
		public int getLabelIdByAlias(String alias) {
			Integer id = (Integer) session.selectOne("label.getLabelIdByAlias",alias);
			if(id!=null){
				return id;
			}else{
			    return 0;
			}
		}

		@Override
		public List<LabelProduct> getLabelByProductId(int productId) {
			// TODO Auto-generated method stub
			return session.selectList("label.getLabelByProductId",productId);
		}

		@Override
		public Products getProductById(int productId) {
			// TODO Auto-generated method stub
			return (Products) session.selectOne("Products.getProductById2",productId);
		}

		@Override
		public int updateProductByMap(Map<String, Object> m) {
			// TODO Auto-generated method stub
			return session.update("Products.updateProductByMap",m);
		}

		@Override
		public int updateLabelByMap(Map<String, Object> m) {
			return session.update("label.updateLabelByMap",m);
		}

		@Override
		public List<String> getPicUrlsByProductId(int pid) {
			// TODO Auto-generated method stub
			return session.selectList("BgPic.getPicUrlsByProductId",pid);
		}

		@Override
		public List<Orders> getOrdersByTradeId(Long tradeId) {
			// TODO Auto-generated method stub
			return session.selectList("orders.getOrdersByTradeId",tradeId);
		}
		public List<Orders> getOrdersByTradeId2(Long tradeId) {
			// TODO Auto-generated method stub
			return session.selectList("orders.getOrdersByTradeId2",tradeId);
		}

		@Override
		public int updateProductionState(Map<String, Object> m) {
			// TODO Auto-generated method stub
			return session.update("orders.updateProductionState",m);
		}

		@Override
		public int getLabelIdByMap(Map<String, Object> map) {
			// TODO Auto-generated method stub
			Integer i = (Integer)session.selectOne("label.getLabelIdByMap",map);
			if(i!=null){
				return i;
			}
			return 0;
		}

		@Override
		public int getOrderCountByMap(Map<String, Object> m) {
			// TODO Auto-generated method stub
			return (Integer) session.selectOne("orders.getOrderCountByMap",m);
		}

		@Override
		public List<Orders> getOrdersByMap(Map<String, Object> m) {
			// TODO Auto-generated method stub
			return session.selectList("orders.getOrdersByMap",m);
		}

		@Override
		public Integer checkProductionState(String orderId) {
			// TODO Auto-generated method stub
			return (Integer) session.selectOne("orders.checkProductionState",orderId);
		}

		@Override
		public Integer syncOrders(List<Orders> oList) {
			int n = 0;
			for(Orders o:oList){
				int i = session.update("orders.updateOrderByOrder",o);
				if(i==0){
					i = session.insert("orders.createOrders2",o);
					n+=i;
				}
				if(o.getRefundid()!=null){
					saveRefundOrder(o.getRefundid(),o);
				}
			}
			return n;
		}

		private void saveRefundOrder(Long refundid,Orders o){
			RefundGetRequest req=new RefundGetRequest();
			req.setFields("refund_id, alipay_no, tid, oid, buyer_nick, seller_nick, total_fee, status, created, refund_fee, good_status, has_good_return, payment, reason, desc, num_iid, title, price, num, good_return_time, company_name, sid, address, shipping_type, refund_remind_timeout");
			req.setRefundId(refundid);
			String sessionKey = MyTaobaoUtil.getSessionKey(o.getSellername());
			try {
				RefundGetResponse response = MyTaobaoUtil.client.execute(req , sessionKey);
				Refund refund = response.getRefund();
				RefundOrder rOrder = new RefundOrder();
				rOrder.setRefundid(refundid);
				rOrder.setOrderid(o.getOrderId());
				rOrder.setCreated(refund.getCreated());
				rOrder.setPayment(refund.getPayment());
				rOrder.setRefundFee(refund.getRefundFee());
				rOrder.setReason(refund.getReason());
				rOrder.setTitle(refund.getTitle());
				rOrder.setTotalFee(refund.getPrice());
				rOrder.setTradeid(refund.getTid());
				rOrder.setNum(refund.getNum());
				rOrder.setBuyerNick(refund.getBuyerNick());
				System.out.println(rOrder);
				session.delete("refundOrder.deleteRefundOrder",refund.getRefundId());
				session.insert("refundOrder.saveRefundOrder",rOrder);
			} catch (ApiException e) {
				e.printStackTrace();
			}
		}
		
		@Override
		public PrintInfo getPrintInfo(String companyCode) {
			// TODO Auto-generated method stub
			return (PrintInfo) session.selectOne("printInfo.getPrintInfo",companyCode);
		}

		@Override
		public List<String> getAllSellername() {
			// TODO Auto-generated method stub
			return session.selectList("orders.getAllSellername");
		}

		@Override
		public boolean checkCartypeByName(String swfuploadFileName) {
			long count = (Long)session.selectOne("cartype.checkCartypeByName",swfuploadFileName);
			if(count==0){
				return true;
			}
			return false;
		}

		@Override
		public List<OrderStatistics> getOrderStatistics(Map<String, Object> m) {
			Map<String,Object>map = new HashMap<String,Object>();
			List<OrderStatistics> orderStatistics = session.selectList("orders.getOrderStatistics",m);
			return orderStatistics;
		}

		@Override
		public List<RefundOrder> getRefundOrder(Map<String, Object> map) {
			// TODO Auto-generated method stub
			return session.selectList("refundOrder.getRefundOrderList",map);
		}

		@Override
		public void updateOrderByMap(Map<String, Object> m) {
			session.update("orders.updateOrderByMap",m);
		}
}
















